//
//  MessageSendModel.m
//  TEXT
//
//  Created by liubo on 2023/10/18.
//  Copyright © 2023 刘博. All rights reserved.
//

#import "MessageSendModel.h"
#import <objc/runtime.h>
#import "ForwardModel.h"

@implementation MessageSendModel

void dynamicMethodIMP(id self, SEL _cmd)
{
    // implementation ....
}

+ (BOOL)resolveInstanceMethod:(SEL)sel
{
    if (sel == @selector(test)) {
       // class_addMethod([self class], sel, (IMP) dynamicMethodIMP, "v@:");
    }
    return NO;
}

//- (id)forwardingTargetForSelector:(SEL)aSelector
//{
//    return [ForwardModel new];
//}


- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector
{
    if (aSelector == @selector(test)) {
          NSLog(@"%s",__func__);
          return [NSMethodSignature signatureWithObjCTypes:"v@:"];
      }
      return [super methodSignatureForSelector:aSelector];
}

-(void)forwardInvocation:(NSInvocation *)anInvocation{
    NSLog(@"%s",__func__);
    SEL aSelector = [anInvocation selector];
    ForwardModel *teacher = [ForwardModel alloc];
    if ([teacher respondsToSelector:aSelector]) {
        [anInvocation invokeWithTarget:teacher];
    }else{
        [super forwardInvocation:anInvocation];
    }
}

@end
